package com.trivia

class SaveStatsService {

    static transactional = true

    def saveStats(String stats) {
		
		def items = stats.split("&")
		
		items.each {
			def item = it.split(";")
			
			Question question = Question.get(Long.parseLong(item[0]))
			
			Answer answer
			
			try{
				answer = Answer.get(Long.parseLong(item[1]))				
			}catch(Exception ex){
				answer = null;
			}
			
			try{
				Stat stat = new Stat(question:question,answer:answer)
				stat.save()
			}catch(Exception ex){
				ex.printStackTrace()
			}
			
		}
    }
	
}
